<h2><%= @item.name %>照片</h2>

<div class="actions">
<span><%= link "返回列表", to: item_path(@conn, :index) %></span>
</div>

<%= form_for @changeset, item_photo_path(@conn, :create, @item), [multipart: true], fn f -> %>
  <%= if @changeset.action do %>
    <div class="alert alert-danger">
      <p>Oops, something went wrong! Please check the errors below.</p>
    </div>
  <% end %>
  <div class="form-group">
    <a data-toggle="collapse" data-target=".uploader-c">上传照片</a>
  </div>
  <div class="uploader-c collapse">
    <div class="form-group">
      <label>照片</label>
      <%= file_input f, :photos, name: "photo[photos][]", class: "form-control", multiple: true %>
    </div>

    <div class="form-group">
      <%= label f, :kind, "类别", class: "control-label" %>
      <%= select f, :kind, [{"室内", "1"}, {"小区", "2"}, {"周边", "3"}], class: "form-control" %>
      <%= error_tag f, :kind %>
    </div>

    <div class="form-group">
      <%= submit "Submit", class: "btn btn-primary" %>
    </div>
  </div>
<% end %>


<ul class="photos">
<%= if length(@photos) == 0 do %>
  <li class="text-center">
  没有照片 <a data-toggle="collapse" data-target=".uploader-c">上传照片</a>
  </li>
<% end %>
<%= for photo <- @photos do %>
    <li class="text-center">
      <div><%= kind_name(photo.kind) %></div>
      <div>
        <a class="photo" href="<%= photo.url %>">
        <%= img_tag(photo.url <> "-thumb", class: "thumb") %>
        </a>
      </div>

      <div>
        <span><%= link "Delete", to: photo_path(@conn, :delete, photo), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %></span>
      </div>
    </li>
<% end %>
</ul>